//
//  CloseNewsSubView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/25.
//

import UIKit

class CloseNewsSubView: UIView {

    init(item:CloseMenuItem) {
        super.init(frame: .zero)
        let icon = UIImageView()
        icon.image = UIImage(named: item.imageName)?.withRenderingMode(.alwaysTemplate)
        icon.tintColor = B333_COLOR
        addSubview(icon)
        icon.snp.makeConstraints({
            $0.top.equalTo(20)
            $0.left.equalTo(15)
            $0.width.height.equalTo(20)
            $0.bottom.equalToSuperview().inset(20)
        })
        let messageLabel = UILabel()
        addSubview(messageLabel)
        messageLabel.textColor = B000_COLOR
        messageLabel.font = Font_Size_15
        if item.subTitle == "" {
            messageLabel.text = item.title
        }else{
            messageLabel.attributedText = "\(item.title)\n\(item.subTitle)".getAttributedString(item.subTitle, subColor: B999_TITLE_COLOR, subFont: Font_Size_12,lineSpace: 5)
        }
        messageLabel.numberOfLines = 2
        messageLabel.snp.makeConstraints({
            $0.left.equalTo(icon.snp.right).offset(10)
            $0.centerY.equalToSuperview()
        })
        if item.items.count>0 {
            let arrow = UIImageView(image: UIImage(named: "arrowright")?.withRenderingMode(.alwaysTemplate).reSizeImage(reSize: CGSize.init(width: 20, height: 20)))
            addSubview(arrow)
            arrow.snp.makeConstraints({
                $0.centerY.equalToSuperview()
                $0.right.equalToSuperview().inset(15)
            })
        }
        addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(tap)))
    }
    @objc func tap(){
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
struct CloseMenuItem{
    var title:String
    var subTitle:String
    var imageName:String
    var items:Array<CloseMenuItem>
    init(title:String,subTitle:String,imageName:String,item:Array<CloseMenuItem>) {
        self.title = title
        self.subTitle = subTitle
        self.imageName = imageName
        self.items = item
    }
    init() {
        title = ""
        subTitle = ""
        imageName = ""
        items = []
    }
}
